import config from "@/config"
import http from "@/utils/request"
/**
 * 供应商
 */
export default {
  selectVendorList: {
    url: `${config.API_URL}/vendor/list`,
    name: "获取供应商列表",
    get: function (data = {}) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },
  getVendorById: {
    url: `${config.API_URL}/vendor/detailById`,
    name: "根据id获取供应商详情",
    get: function (data = {}) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },
  addVendor: {
    url: `${config.API_URL}/vendor/add`,
    name: "添加供应商",
    post: function (data = {}) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },
  editVendor: {
    url: `${config.API_URL}/vendor/update`,
    name: "修改供应商",
    post: function (data = {}) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },
  deleteVendor: {
    url: `${config.API_URL}/vendor/delete`,
    name: "删除供应商",
    post: function (data = {}) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  // 供应商分类
  vendorType: {
    getVendorTypeList: {
      url: `${config.API_URL}/vendorType/page`,
      name: "获取供应商分类列表",
      get: function (data = {}) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    addVendorType: {
      url: `${config.API_URL}/vendorType/add`,
      name: "添加供应商分类",
      post: function (data = {}) {
        return new Promise((resolve, reject) => {
          http.post(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    updateVendorType: {
      url: `${config.API_URL}/vendorType/update`,
      name: "修改供应商分类",
      post: function (data = {}) {
        return new Promise((resolve, reject) => {
          http.post(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    deleteVendorType: {
      url: `${config.API_URL}/vendorType/delete`,
      name: "删除供应商分类",
      post: function (data = {}) {
        return new Promise((resolve, reject) => {
          http.postParam(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    updateVendorTypeState: {
      url: `${config.API_URL}/vendorType/updateState`,
      name: "是否禁用供应商分类",
      post: function (data = {}) {
        return new Promise((resolve, reject) => {
          http.postParam(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
  }
}